package utils

import (
	"fmt"
	"io/ioutil"
	"log"
	"net/http"

	"github.com/linclaus/stock/pkg/gografana"
)

func GetGrafanaRenderImage(board gografana.Board) {
	url := "http://192.168.203.181:3000/render/d-solo/CmEVUHoGk/sh000001-shang-zheng-zhi-shu?orgId=1&from=1608259987021&to=1608432787021&panelId=1&width=1000&height=500&tz=Asia%2FShanghai"
	var client = http.Client{}
	req, err := http.NewRequest("GET", url, nil)
	req.Header.Add("Accept", "application/json")
	resp, err := client.Do(req)
	if err != nil {
		log.Fatalf("http.Get -> %v", err)
		return
	}
	data, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		log.Fatalf("ioutil.ReadAll -> %v", err)
		return
	}

	defer resp.Body.Close()
	err = ioutil.WriteFile(fmt.Sprintf("%s/%s", "./", "fileName.png"), data, 0666)
	if err != nil {
		log.Fatalf("ioutil.WriteFile -> %v", err)
		return
	}
}
